/**
 * Created by Administrator on 2016/12/23.
 */
//console.log("hello world");
//1.引入http模块,该模块用来创建http服务器
var http=require('http');

//2.利用该模块创建http服务器
var server=http.createServer(function (req, res) {
    res.writeHead(200,{'Content-Type': 'text/html'});
    //res.writeHead(200,{'charset':'utf-8'});
    res.write('<head><meta charset="utf-8"/></head>');
    console.log(req.url);
    console.log(req.method);
    //根据用户请求不同, 发送不同的数据
    if(req.url=='/'){
        res.write("this is the scheme page");
    }else if (req.url=='/index'){
        res.write('this is the index page.');
    }else if (req.url=='/json'){
        res.write('{"name":"zhangsan","age":23}');
    }
    //res.write('あなだはなにものだ？');
    res.end();
});

//3.给服务绑定端口号
server.listen(8888,function () {
    console.log('服务器已启动');
});
